home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_10 / saks / genq5.h < prev    next >
C/C++ Source or Header  |  1994-08-08  |  891b  |  51 lines

  1. Listing 1 - class and inline member function definitions for a generic 
  2. queue using void * and an nested iterator class
  3.  
  4. //
  5. // genq5.h - generic queue of void *
  6. // with an iterator class
  7. //
  8.  
  9. #include <iostream.h>
  10.  
  11. class genq
  12.     {
  13. private:
  14.     struct cell
  15.         {
  16.         cell(void *e, cell *p);
  17.         cell *next;
  18.         void *element;
  19.         };
  20.     cell *first, *last;
  21. public:
  22.     genq();
  23.     void append(void *e);
  24.     int remove(void *&e);
  25.     class iterator;
  26.     friend class iterator;
  27.     class iterator
  28.         {
  29.     public:
  30.         iterator(genq &q);
  31.         void *next();
  32.     private:
  33.         cell *pc;
  34.         };
  35.     };
  36.  
  37. inline genq::cell::cell(void *e, cell *p)
  38.     : element(e), next(p)
  39.     {
  40.     }
  41.  
  42. inline genq::iterator::iterator(genq &q)
  43.     : pc(q.first)
  44.     {
  45.     }
  46.  
  47. inline genq::genq() : first(0), last(0)
  48.     {
  49.     }
  50.  
  51.